var fs = require("fs");
var path = require("path");


var mslibrary = require('ms-common-library');

var qr_image = require("qr-image");

module.exports = function (UC, source, config, ArFor, cache, package) {

    //res.redirect

    //getLocalhost
    var router = function (req, res, next) {
        var body = req.body;
        var _options = {
            customize: null,
            ec_level: "M",
            margin: 4,
            parse_url: false,
            size: 5,
            type: "png"
        };
        for (var key in _options) {
            if (body[key]) {
                _options[key] = body[key];
            }
        };
        var value = body.value;
        if (value) {
            value = value.replace("{Domain}", config.getDomain(req));
            value = value.replace("{domain}", config.getdomain(req));
        };
        var linkid = config.RandomString(32);
        new source({
            "SQL": "INSERT INTO [qrcodelist] (linkid, value, _expansion,Coinkey,Creation) VALUES ('{linkid}','{value}','{_expansion}','{Coinkey}',datetime('now','+8 hour'));",
            "type": "add"
        }, {
            Coinkey: '-',
            value: value,
            _expansion: JSON.stringify(_options),
            linkid: linkid,
        }, function (db) {
            res.Json({
                linkid: linkid
            });
        })
    }
    return router;

}